import 'package:flutter/material.dart';
import '../../core/app_theme.dart';
import '../../route/router.dart';

class ProfilePage extends StatelessWidget {
  const ProfilePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('我的')),
      body: ListView(
        children: [
          // 用户信息
          Container(
            padding: const EdgeInsets.all(16),
            color: Colors.white,
            child: Row(
              children: [
                const CircleAvatar(
                  radius: 40,
                  backgroundColor: AppTheme.primaryLight,
                  child: Icon(Icons.person, size: 40, color: Colors.white),
                ),
                const SizedBox(width: 16),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text('用户名', style: TextStyle(fontSize: 18)),
                    TextButton(
                      onPressed: () {
                        print('登录/注册');
                        AppRouter.push(context, RouterPath.login);
                        //Navigator.pushNamed(context, RouterPath.login);
                      },
                      child: const Text('登录/注册'),
                    ),
                  ],
                ),
              ],
            ),
          ),
          const SizedBox(height: 8),
          // 功能列表
          _buildListTile(Icons.list, '我的订单', '查看全部订单'),
          _buildListTile(Icons.favorite, '我的收藏'),
          _buildListTile(Icons.location_on, '收货地址', null, () {
            AppRouter.push(context, RouterPath.addresses);
          }),
          _buildListTile(Icons.settings, '设置'),
          _buildListTile(Icons.help, '帮助中心'),
          _buildListTile(Icons.info, '关于我们'),
        ],
      ),
    );
  }

  Widget _buildListTile(
    IconData icon,
    String title, [
    String? subtitle,
    VoidCallback? onTap,
  ]) {
    return Card(
      margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
      child: ListTile(
        leading: Icon(icon, color: AppTheme.primaryColor),
        title: Text(title),
        subtitle: subtitle != null ? Text(subtitle) : null,
        trailing: const Icon(Icons.chevron_right),
        onTap: onTap, // 使用传入的onTap回调
      ),
    );
  }
}
